package main.request;

import java.io.IOException;

import utils.Debug;
import main.process.FtpRequest;



public class RequestPass implements ProcessRequestInterface {

	private static class SingletonHolder
	{		
		/** Instance unique non préinitialisée */
		private final static RequestPass instance = new RequestPass();
	}
	
	public static RequestPass getInstance()
	{
		return SingletonHolder.instance;
	}
	
	@Override
	public void processRequest(String[] request, FtpRequest ftp) throws IOException {
		
		Debug.debug(this.getClass().getName(), request, ftp.getDebug());
		
		if(!request[0].equals("PASS"))
		{
			next(request, ftp);
		}
		else
		{
			if(ftp.getNameUser().equals("ftp"))
		
		{
			ftp.write("230 ftp logged in\n");
		}
		else
		{
			ftp.write("332 user unknown, please login\n");
		}
		}
	}

	@Override
	public void next(String[] request, FtpRequest ftp) throws IOException {
		RequestPasv.getInstance().processRequest(request, ftp);
	}

}
